//
//  WBNetworkManager+Extension.swift
//  赝品微博
//
//  Created by 刘浩林 on 2016/11/7.
//  Copyright © 2016年 刘浩林. All rights reserved.
//

import Foundation


//MARK:- 封装新浪微博的网络请求方法
extension WBNetworkManager{

     /// 加载微博数据字典数组
    ///
    /// - Parameters:
    ///   - since_id: 下拉刷新
    ///   - max_id: 上拉刷新
    ///   - completion: 完成回调[list:微博字典数组/是否成功]
    func statusList(since_id: Int64 = 0, max_id:Int64 = 0, completion: @escaping (_ list:[[String:Any]]?,_ isSuccess:Bool)->()) -> () {

        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"

        let params = ["since_id":since_id,"max_id":(max_id > 0 ? max_id-1 : 0)]

        tokenRequest(URLString: urlString, parameters: params, completion: { (json,isSuccess) in
            //print(json)

            guard let dataDict = json as? [String:Any] else{
                return
                            }
            //从json中获取statuses字典数组/
            //如果as?失败,result等于nil
            //提示:服务器返回的字典数组,就是按照时间的倒序排序的
            let result = dataDict["statuses"]
            completion(result as! [[String : Any]]?, isSuccess)


        })

    }

}
